﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace _8280WEBSocket
{
    public partial class AttachmentForm : Form
    {
        public AttachmentForm()
        {
            InitializeComponent();
        }

        Dictionary<string, string> Attachment = new Dictionary<string, string>();
        private void btnAdd_Click(object sender, EventArgs e)
        {
            if (Attachment.ContainsKey(txtKey.Text))
            {
                MessageBox.Show("key=" + txtKey.Text, "已经存在");
                return;
            }
            Attachment.Add(txtKey.Text, txtValue.Text);
            var index = gvKeyValue.Rows.Add();
            gvKeyValue.Rows[index].Cells[0].Value = txtKey.Text;
            gvKeyValue.Rows[index].Cells[1].Value = txtValue.Text;
        }

        private void btnDelete_Click(object sender, EventArgs e)
        {
            if (gvKeyValue.SelectedRows.Count == 0)
            {
                MessageBox.Show("请选择需要删除的内容", "提示");
                return;
            }
            var row = gvKeyValue.SelectedRows[0];
            var key = row.Cells[0].Value.ToString();
            if (Attachment.ContainsKey(key))
            {
                Attachment.Remove(key);
            }
            gvKeyValue.Rows.Remove(row);
            MessageBox.Show("删除成功", "提示");
        }
    }
}
